package engine.logic.loading.effect
{
	import com.greensock.TweenLite;
	
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Stage;
	import flash.events.Event;
	
	import newx.StageInfo;
	import newx.com.ResManager;

	public class Fade extends AbstractTransitionEffect
	{
		public function Fade()
		{
			super();
			init();
		}
		
		private var _effectMc:MovieClip;
		private var _shape:Shape = new Shape();
		
		private var _w:Number = 1000;
		private var _h:Number = 600;
		
		private function init():void
		{
			_effectMc = ResManager.newResClass("starry_8") as MovieClip;
			_effectMc.stop();
			addChild(_effectMc);
		}
		
		override public function effectIn():void
		{
			_effectMc.gotoAndPlay(1);
			resize();
			_shape.addEventListener(Event.ENTER_FRAME,frameHandler);
		}
		
		override public function set width(value:Number):void
		{
			_w = value;
		}
		
		override public function set height(value:Number):void
		{
			_h = value;
		}
		
		private function resize():void
		{
			_effectMc.width = _w;
			_effectMc.height = _h;
		}
		
		override public function effectOut():void
		{
			_effectMc.gotoAndPlay(15);
			resize();
			_shape.addEventListener(Event.ENTER_FRAME,frameHandler);
		}
		
		private function frameHandler(e:Event):void
		{
			resize();
			if(_effectMc.currentFrame == 14)
			{
				_effectMc.stop();
				_shape.removeEventListener(Event.ENTER_FRAME,frameHandler);
				
				dispatchEvent(new TransitionEffectEvent(TransitionEffectEvent.EffectInOver));
			}
			else if(_effectMc.currentFrame == _effectMc.totalFrames)
			{
				_effectMc.stop();
				_shape.removeEventListener(Event.ENTER_FRAME,frameHandler);
				
				dispatchEvent(new TransitionEffectEvent(TransitionEffectEvent.EffectOutOver));
			}
		}
		
	}
}